Flowctl : Network flow control

更新时间:
2024-05-15
下载文档

Flowctl : Network flow control

This module is a network flow control module.

User can use the following code to import the flowctl module.

var flowctl = require('router/flowctl');

Support

The following shows flowctl module APIs available for each permissions.

 User ModePrivilege Mode
flowctl.if 
flowctl.ip 
flowctl.tcp 
flowctl.udp 
flowctl.get 
flowctl.delete 

Flowctl Object

flowctl.if(ifname, upLimit, downLimit[, bufSize])

  • ifname {String} Network interface name.
  • upLimit {Integer} Uplink speed limit in Bytes per second.
  • downLimit {Integer} Downlink speed limit in Bytes per second.
  • bufSize {Integer} Kernel buffer size bytes of this speed limit rule (16KB~128KB). default: 32KB.
  • Returns: {Integer} Index number of this rule.

Add a speed limit rule: set the total speed limit parameters of a network interface.

Example

// Add a speed limit rule: 
// Set the uplink rate limit of en1 interface to 100KBps and the downlink rate limit of 200KBps.
flowctl.if('en1', 100 * 1000, 200 * 1000);

flowctl.ip(ifname, ipStart, ipEnd, upLimit, downLimit[, bufSize])

  • ifname {String} Network interface name.
  • ipStart {String} Starting IP address.
  • ipEnd {String} End IP address.
  • upLimit {Integer} Uplink speed limit in Bytes per second.
  • downLimit {Integer} Downlink speed limit in Bytes per second.
  • bufSize {Integer} Kernel buffer size bytes of this speed limit rule (16KB~128KB). default: 32KB.
  • Returns: {Integer} Index number of this rule.

Add a rate limit rule to the specified IP address segment of the specified network interface.

Example

// 'ipStart' address must be less than 'ipEnd'
flowctl.ip('br4', '10.0.0.1', '10.0.0.10', 100 * 1000, 200 * 1000);

flowctl.tcp(ifname, ipStart, ipEnd, portStart, portEnd, upLimit, downLimit[, bufSize])

  • ifname {String} Network interface name.
  • ipStart {String} Starting IP address.
  • ipEnd {String} End IP address.
  • portStart {Integer} Starting TCP port.
  • portEnd {Integer} End TCP port.
  • upLimit {Integer} Uplink speed limit in Bytes per second.
  • downLimit {Integer} Downlink speed limit in Bytes per second.
  • bufSize {Integer} Kernel buffer size bytes of this speed limit rule (16KB~128KB). default: 32KB.
  • Returns: {Integer} Index number of this rule.

Add a rate limit rule to the specified IP address segment TCP protocol connection of the specified network interface.

Example

// 'portStart' must be less than 'portEnd'
flowctl.tcp('br4', '10.0.0.1', '10.0.0.10', 80, 80, 100 * 1000, 200 * 1000);

flowctl.udp(ifname, ipStart, ipEnd, portStart, portEnd, upLimit, downLimit[, bufSize])

  • ifname {String} Network interface name.
  • ipStart {String} Starting IP address.
  • ipEnd {String} End IP address.
  • portStart {Integer} Starting UDP port.
  • portEnd {Integer} End UDP port.
  • upLimit {Integer} Uplink speed limit in Bytes per second.
  • downLimit {Integer} Downlink speed limit in Bytes per second.
  • bufSize {Integer} Kernel buffer size bytes of this speed limit rule (16KB~128KB). default: 32KB.
  • Returns: {Integer} Index number of this rule.

Same as flowctl.tcp(), but suitable for UDP protocol.

Example

// 'portStart' must be less than 'portEnd'
flowctl.udp('br4', '10.0.0.1', '10.0.0.10', 1024, 2048, 100 * 1000, 200 * 1000);

flowctl.get()

  • Returns: {Array} List of all limited speed rules added previously.

Each rule is an object in the array, which contains the following properties:

  • ifname {String} Network interface name.
  • index {Integer} Index number of this rule.
  • rule {String} Type of this rule: 'IF', 'IP', 'TCP' or 'UDP'.
  • upLimit {Integer} Uplink speed limit in Bytes per second.
  • downLimit {Integer} Downlink speed limit in Bytes per second.
  • bufSize {Integer} Kernel buffer size bytes of this speed limit rule.
  • ipStart {String} Starting IP address.
  • ipEnd {String} End IP address.
  • portStart {Integer} Starting TCP or UDP port.
  • portEnd {Integer} End TCP or UDP port.

Example

var rules = flowctl.get();

console.log(rules);

flowctl.get(ifname)

  • ifname {String} Network interface name.
  • Returns: {Array} List of all limited speed rules for the specified network interface added previously.

Same as flowctl.get(), only list the rules for the specified network interface.

Example

var rules = flowctl.get('en1');

console.log(rules);

flowctl.get(index)

  • index {Integer} Index number of rule.
  • Returns: {Object} Rule object corresponding to index.

Same as flowctl.get(), but only get the rule specified by index.

Example

var index = flowctl.if('en1', 100 * 1000, 200 * 1000);
var rule = flowctl.get(index);

console.log(rule);

flowctl.delete()

  • Returns: {Boolean} Whether the operation was successful.

Delete all speed limit rules added in this process.

Example

flowctl.delete();

flowctl.delete(ifname)

  • ifname {String} Network interface name.
  • Returns: {Boolean} Whether the operation was successful.

Delete all speed limit rule of the specified interface.

flowctl.delete(index)

  • index {Integer} Index number of this rule.
  • Returns: {Boolean} Whether the operation was successful.

Delete the speed limit rule of the specified index number.

Example

var index = flowctl.if('en1', 100 * 1000, 200 * 1000);
flowctl.delete(index);
文档内容是否对您有所帮助?
有帮助
没帮助